package com.zhangh.summer.admin.support.exception;

import com.zhangh.summer.admin.support.base.JsonResponse;
import com.zhangh.summer.admin.support.boot.interfaces.OnAppConfigConditional;
import com.zhangh.summer.admin.support.boot.common.AppConfigEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by zhanghui on 2019-04-29.
 * restful controller 统一异常拦截处理
 */
@ControllerAdvice(annotations = {RestController.class})
@OnAppConfigConditional(AppConfigEnum.WEBMVC_CONFIGURATION_ENABLE)
@Slf4j
@Order(-2)
public class BizExceptionHandler {


    @ExceptionHandler(BizException.class)
    @ResponseBody
    public String handleBizException(HttpServletRequest req, Exception e)throws Exception{
        String msg=e.getMessage();//e.getMessage();
        log.error(msg);
        return new JsonResponse(false,5000,msg).toJson();
    }

}
